import request from '@/utils/request'
export default {
  //   GET / admin / acl / user / { page } / { limit }
  // 获取管理用户分页列表
  reqPageUserData(page, limit, username) {
    return request.get(`/admin/acl/user/${page}/${limit}`, {
      params: {
        username
      }
    })
  },

  //POST /admin/acl/user/save
  // PUT / admin / acl / user / update
  //添加或编辑用户
  async reqAddOrUpdateUser(addUserForm) {
    let { id, username, nickName, password } = addUserForm
    try {
      if (addUserForm.id) {
        return await request.put(`/admin/acl/user/update`, {
          id,
          username,
          nickName,
          password
        })

      } else {
        return await request.post(`/admin/acl/user/save`, {
          username,
          nickName,
          password
        })
      }
    } catch (error) {
      return new Promise.reject(error)
    }

    // return request.post(`/admin/acl/user/save`, {
    //   username,
    //   nickName,
    //   password
    // })
  },
  //DELETE /admin/acl/user/batchRemove
  //根据id列表删除管理用户
  // reqRemoveUserList(list) {
  //   return request.delete('/admin/acl/user/batchRemove')
  //  }该接口待测

  //获取用户角色数据
  // GET / admin / acl / user / toAssign / { userId }
  // http://localhost:3000/app-dev/admin/acl/user/toAssign/1571028515873853442
  reqUserRoleData(userId) {
    return request.get(`/admin/acl/user/toAssign/${userId}`)
  },

  //给用户设置角色
  // / app - dev / admin / acl / user / doAssign ? userId = 1571344160368857089 & roleId=1, 1571145908759531521
  reqSetAssign(userId, roleId) {
    // return request.post('/admin/acl/user/doAssign', null, {
    //   params: {
    //     userId,
    //     roleId
    //   }
    // })
    return request.post(`/admin/acl/user/doAssign?userId=${userId}&roleId=${roleId}  `)
  },

  //删除用户
  // DELETE / admin / acl / user / remove / { id }
  reqDeleteUser(id) {
    return request.delete(`/admin/acl/user/remove/${id}`)
  }

}